<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>首页</title>
    <link href="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">

    <%--  引入导航条 --%>
    <jsp:include page="common/nav.jsp"/>
    <div>
        <table class="table table-bordered table-hover">
        <tr>
            <th>姓名</th>
            <th>身份证</th>
            <th>性别</th>
            <th>薪资</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${page.list}" var="e">
            <tr id="${e.id}">
                <td>${e.name}</td>
                <td>${e.personNumber}</td>
                <td>${e.sex}</td>
                <td>${e.sal}</td>
                <td>
                     <button class="btn btn-info btn-xs btn_edit" >更改</button>
                    <button class="btn btn-danger btn-xs btn_del">删除</button>
                </td>
            </tr>
        </c:forEach>
    </table>
        <nav>
            <ul class="pager">
                <li><a href="listEmps?pageNo=${page.pre}&pageSize=${page.pageSize}">上一页</a></li>
                <li> ${page.pageNo}/ ${page.pageCount} </li>
                <li><a href="listEmps?pageNo=${page.next}&pageSize=${page.pageSize}">下一页</a></li>
            </ul>
        </nav>
    </div>
</div>
</body>


<script>
    $(function () {
        $(".btn_del").click(function () {
            var $tr = $(this).parents("tr");
            var idValue = $tr.attr("id");
            layer.confirm('确定要删除吗?', {icon: 3, title:'系统提示'}, function(index){
                //xmlhttprequest
                $.post("/delEmp",{"id":idValue},function (data) {
                    // var json = JSON.parse(data);
                    if(data["success"]){
                      layer.msg("操作成功",{time:700},function () {
                         //刷新
                          window.location.reload();
                      });
                    }
                },"json");
                layer.close(index);
            });

        });

        $(".btn_edit").click(function () {
            var $tr = $(this).parents("tr");
            var id = $tr.attr("id");
            layer.open({
                title:'编辑员工',
                type: 2,
                content: '/showEmp4Edit?id='+id,
                area: ['600px', '500px']
            });

        });
    });
</script>
</html>